<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
<head>

<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="js/plugin/jquery-jtemplates.js" type="text/javascript"></script>
<script src="js/plugin/jquery-ui-1.8.12.custom.min.js"
	type="text/javascript"></script>
<script src="js/plugin/jquery.bgiframe-2.1.2.js" type="text/javascript"></script>
<script src="js/plugin/jquery.validate.min.js" type="text/javascript"></script>
<script src="js/plugin/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="js/hnl-common.js" type="text/javascript"></script>
<script src="js/hnl-search.js" type="text/javascript"></script>
<script src="js/hnl-dialogObj.js" type="text/javascript"></script>
<link href="css/jquery/jquery.ui.all.css" rel="stylesheet"></link>
<link href="css/jquery/jquery.ui.dialog.css" rel="stylesheet"></link>
<link href="css/search.css" rel="stylesheet"></link>
<link href="css/hnl-main.css" rel="stylesheet"></link>
<link href="css/hnl-table.css" rel="stylesheet"></link>

<script>
	$(document).ready(
			function() {
				$("#main").addClass("ui-widget");
				
				/*Init forms*/
				$("#dialog:ui-dialog").dialog("destroy");

				/*Dialogs */
				$("#dialog-alert").dialog({
					autoOpen : false,
					height : 220,
					width : 320,
					modal : true,
					//TODO: implement this dialig
				});
				
				$("#dialog-confirm").dialog({
					autoOpen : false,
					//resizable: false,
					height : 220,
					width : 320,
					modal : true,
					buttons : {
						"Confirm" : function() {
							$(this).dialog("close");
							var idAry =  getDeleteArray();
							
							if(idAry.length==0){										
								$("#alert-msg").html("No consultant(s) selected. !!");
								$("#dialog-alert").dialog("open");
							}
							$.ajax({
								type:"POST",
								url:"/hnl/DeleteConsultant.do",
								data:{	
									//talentID:tid,
									deleteList:idAry.join(",")
								},
								dataType:"json",
								success: function(data) {
									consultantTable = updateTableTemplate(data, "#allCousultant",
											"/hnl/template/consultantListTemplate.jsp",
											"#consultantListTable", false, allRowFunction, "checkboxAll");
									//initReferralTB();
								}	
							});	
						},
						Cancel : function() {
							$(this).dialog("close");
						}
					}
				});
				/*Draw table*/

				var allRowFunction = function() {
					/* Get the position of the current data from the node */
					var aPos = consultantTable.fnGetPosition(this);
					/* Get the data array for this row */
					var aData = consultantTable.fnGetData(aPos[0]);
					//alert(aData[1]);
					if(aPos[1]!=0){
						window.location.replace("consultantInfo.jsp?userID="
								+ aData[1]);
					}
					
				};

				$.getJSON("/hnl/LoadConsultantList.do", function(data) {
					consultantTable = updateTableTemplate(data, "#allCousultant",
							"/hnl/template/consultantListTemplate.jsp",
							"#consultantListTable", false, allRowFunction, "checkboxAll");
				});
				
				/* set value for del checkbox array */
				function getDeleteArray(){
					 var idAry = [];
					$("#consultantListTable input:checkbox.chkBox").each(function(){
						if($(this).is(":checked")){
							idAry.push($(this).val());
						}
					});
					return idAry;
				 }
	
				/*Button action*/
				$("#addConsultant").click(function() {
					window.location.replace("consultantInfo.jsp?userID=''");
				});

				$("#search").click(function() {
					var mailString = $("#email").val();

					$.getJSON("/hnl/SearchConsultantList.do?userEmail="+mailString, function(data) {
						consultantTable = updateTableTemplate(data, "#allCousultant",
								"/hnl/template/consultantListTemplate.jsp",
								"#consultantListTable", false, allRowFunction, "checkboxAll");
					});
				});				
						
				$("#delConsultant").click(function(evt) {
					evt.preventDefault();
					$("#dialog-confirm").dialog("open");
				});
				
				$("#logout").click(function() {
					$("#main").attr("action", "/hnl/UserLogout.do");
					$("#main").attr("method", "post");
					$("#main").submit();
				});

			});


</script>

</head>
<body class="formBody">
	<form id="main">
		<div class="welcomeInfo">
			<table>
				<tr>
					<td>Welcome</td>
					<td class="message1"><c:out value="${loggedInUser.firstname}" />
						<c:out value="${loggedInUser.lastname}" />
					</td>
					<td>(</td>
					<td class="message1"><c:out value="${loggedInUser.email}" />
					</td>
					<td>)</td>
					<td>| <a href="/hnl/dashboard.jsp">Talent Info</a>
					</td>
					<td>| <input class="button_short" id="logout" type="button"
						value="Logout" /></td>
				</tr>
			</table>
		</div>
		<div style="clear: both;"></div>
		<!--  
		<fieldset class="mainFieldSet searchInput" >
			<legend class="mainLegend">Search for Consultant</legend>
			<label for="search">Search E-mail</label> <input id="email" 
				name="email" type="text" value="" /> <input id="search"
				type="button" value="Search" />
		</fieldset>
		-->
		<fieldset class="mainFieldSet" id="consultantMgmtFieldset">
			<legend class="mainLegend">Consultant Management</legend>
			<fieldset class="subFieldSet">
				<legend class="subLegend">Consultant List</legend>
				<div>
					<img id="addConsultant" class="add" src="./images/add.png"></img>&nbsp;&nbsp;
					<img id="delConsultant" class="del" src="./images/del.png"></img>
				</div>
				<div id="allCousultant"></div>
			</fieldset>
		</fieldset>
	</form>

	<div id="dialog-confirm" title="Delete Consultant">
		<p>
			<span class="ui-icon ui-icon-alert"
				style="float: left; margin: 0 7px 20px 0;"></span>Do you really want
			to delete User(s) from the database?
		</p>
	</div>

	<div id="dialog-alert" title="Warning">
		<p>
			<!-- <span class="ui-icon ui-icon-alert"
				style="float: left; margin: 0 7px 20px 0;"></span> -->
		<div id="alert-msg" name="alert-msg"></div>
		</p>
	</div>
</body>
</html>
